<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>axios-config模式</h2>
    <button class="get">axios-get请求</button>
    <button class="post">axios-post请求</button>
    <script src="./lib/axios.js"></script>
    <script>

        const api = 'http://ajax-api.itheima.net/api/robot'
        const api_login = 'http://ajax-api.itheima.net/api/login'

        // 1. 测试get请求
        const getBtn = document.querySelector('.get')

        getBtn.addEventListener('click', function(){
            axios({
                url:api,
                method:'GET',
                params: {
                    spoken:'听我所谢谢你'
                }
            }).then(res => {
                console.log(res)
            })
        })



        // 2. 测试post请求
        const postBtn = document.querySelector('.post')
        postBtn.addEventListener('click', function(){
            axios({
                url:api_login,
                method:'post',
                data:{
                    username:'admin',
                    password:'123456'
                }
            }).then(res => {
                console.log(res)
            })
        })

        // 3. 总结 
        // axios({
        //     url:地址，
        //     method:get/post,
        //     params:{get参数}，
        //     data:{post参数}
        // })
    </script>
</body>
</html>